﻿/*
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is [eden: ECMAScript data exchange notation AS3]. 
  
  The Initial Developer of the Original Code is
  Zwetan Kjukov <zwetan@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2011
  the Initial Developer. All Rights Reserved.
  
  Contributor(s):
  Marc Alcaraz <ekameleon@gmail.com>.
  
*/

package
{
    import core.dump;
    import core.log;
    
    import library.eden.EdenSerializer;
    import library.eden.metadata;
    
    import flash.display.Sprite;
    
    [ExcludeClass]
    [SWF(width="400", height="400", backgroundColor="0xFFFFFF", frameRate="24", pageTitle="eden_test", scriptRecursionLimit="1000", scriptTimeLimit="60")]
    public class eden_test extends Sprite
    {
        public var eden:EdenSerializer;
        
        public function eden_test()
        {
            trace( "hello world" );
            
            metadata.about( true, true );
            
            
            LOG::P
            {
                log.level = log.VERBOSE;
                log.config( { mode: "clean", sep: " " } );
            }
            
            metadata.config.verbose = true;
            metadata.config.enableErrorChecking = false;
            metadata.config.security = true;
            metadata.config.strictMode = true;
            //metadata.config.allowFunctionCall = false;
            
            eden = new EdenSerializer();
            
            var source1:String = <![CDATA[
            /* hello world */
            toto = 123;
            titi = 456;
            a = [];
            a[3] = 3;
            o = {};
            o.bool = true; //hehe
            o.nill = null; /* oups */
            str = "hello world";
            arr = str.split("");
            is = "test";
            mytest = library.eden.metadata.fullname;
            ]]>;
            
            eden.addAuthorized( "library.eden.metadata.fullname" );
            
            var source2:String = <![CDATA[
            /* bonjour le monde */
            xyz = toto;
            test = mytest;
            a[0] = 0;
            a[1] = 1;
            a[2] = 2;
            arr = arr.join( "" );
            var = "something";
            ]]>;
            
            
            
            var source3:String = <![CDATA[
            toto = library.eden.metadata.fullname;
            library.eden.metadata.fullname = "hello world";
            titi = library.eden.metadata.fullname;
            abc = "test";
            tutu = abc;
            xyz = abc.toLowerCase();
            eden = new library.eden.EdenSerializer();
            eden2 = new edser();
            logs = eden.toString();
            logs2 = eden2.toString();
            tutu = library.eden.metadata.version;
            ]]>;
            
            eden.addAuthorized( "library.eden.EdenSerializer.*" );
            eden.addAuthorized( "library.eden.metadata.fullname" );
            eden.addAlias( "edser", "library.eden.EdenSerializer" );
            
            //var result:* = ECMAScript.evaluate( source, metadata.config.enableErrorChecking );
            var result1:* = eden.deserialize( source1, true );
            trace( dump( result1, true ) );
            trace( "comments:\n" + eden.comments );
            trace( "logs:\n" + eden.logs.join("\n") );
            
            var result2:* = eden.deserialize( source2, true );
            trace( dump( result2, true ) );
            trace( "comments:\n" + eden.comments );
            trace( "logs:\n" + eden.logs.join("\n") );
            
            var result3:* = eden.deserialize( source3, true );
            trace( dump( result3, true ) );
            trace( "comments:\n" + eden.comments );
            trace( "logs:\n" + eden.logs.join("\n") );
            
            //trace( "library.eden.metadata.fullname = " + library.eden.metadata.fullname );
        }
    }
}
